<template>
  <div>
    <module-title :title="moduleTitle"></module-title>
    <el-card class="box-card" style="margin-bottom: 20px">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="任务名称">
          <el-input v-model="formInline.taskName" placeholder="任务名称"></el-input>
        </el-form-item>
        <el-form-item label="任务编号"   label-width="100px">
          <el-input v-model="formInline.taskCode" placeholder="任务编号"></el-input>
        </el-form-item>
        <el-form-item label="任务性质"   label-width="100px">
          <el-select v-model="formInline.taskType" placeholder="任务性质">
            <el-option label="单个任务" value="1"></el-option>
            <el-option label="持续任务" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="任务状态">
          <el-select v-model="formInline.status" placeholder="任务状态" style="width: 200px">
            <el-option label="执行完成" value="1"></el-option>
            <el-option label="执行中" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="float: right">
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button @click="emptySearch">清空条件</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="box-card" style="margin-bottom: 20px">
      <el-table
        :data="tableData"
        border
        tooltip-effect="dark"
        style="width: 100%">
        <el-table-column
          prop="taskCode"
          label="任务编号"
          align="center">
        </el-table-column>
        <el-table-column
          prop="taskName"
          label="任务名称"
          align="center">
        </el-table-column>
        <el-table-column
          prop="startTime"
          label="任务执行时间"
          align="center">
        </el-table-column>
        <el-table-column
          prop="taskType"
          label="任务性质"
          align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.taskType === '1'">单个任务</span>
            <span v-else>持续任务</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="endTime"
          label="任务结束时间"
          align="center">
        </el-table-column>
        <el-table-column
          prop="status"
          label="任务状态"
          align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.status === '0'">执行中</span>
            <span v-else>执行完成</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="taskLabel"
          label="任务标签"
          align="center">
          <template slot-scope="scope">
            {{scope.row.taskLabel.replaceAll(',', '')}}
          </template>
        </el-table-column>
        <el-table-column
          prop="appNames"
          label="APP名称"
          align="center">
        </el-table-column>
      </el-table>
      <div class="block"  style="text-align: center">
        <el-pagination
          @current-change="handleCurrentChange"
          :page-size="queryLine.pageSize"
          layout="total, prev, pager, next"
          :total="total">
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import API from "@/network/api/emsApi";
import ModuleTitle from "@/components/content/ModuleTitle.vue";
import {createSign} from "../../../utils/sign";
export default {
    name: "index",
  data() {
    return {
      total: '',
      moduleTitle: "任务详情",
      formInline: {
        taskName: '',
        taskCode: '',
        taskType: '',
        status: '',
        organId: ''
      },
      formSign: {
        sign: ''
      },
      queryLine: {
        pageNum: 1,
        pageSize: 10
      },
      tableData: []
    };
  },
  components: { ModuleTitle },
  created() {
      this.getList()
  },
  methods: {
    async getList() {
      const queryTime = {
        timestamp: +new Date()
      }
      if (this.formInline.taskName === '') {
        delete this.formInline.taskName
      }
      if (this.formInline.taskCode === '') {
        delete this.formInline.taskCode
      }
      if (this.formInline.taskType === '') {
        delete this.formInline.taskType
      }
      if (this.formInline.status === '') {
        delete this.formInline.status
      }
      this.formInline.organId = JSON.parse(localStorage.getItem('updateUserInfo')).organId
      console.log(this.formInline.organId, 'organId');
      this.formSign.sign = createSign(
        JSON.stringify({
          ...this.queryLine,
          ...queryTime,
          ...this.formInline
        })
      )
      await API.queryTaskLog({
        ...this.queryLine,
        ...queryTime,
        ...this.formInline,
        ...this.formSign
      }).then(res => {
        console.log(res, 'res');
        this.tableData = res.data.data.records;
        this.total = res.data.data.total;
      })
    },
    handleCurrentChange(val) {
      this.queryLine.pageNum = val;
      this.getList();
    },
    onSubmit() {
      this.getList();
    },
    emptySearch() {
      this.formInline.taskName = ''
      this.formInline.taskCode = ''
      this.formInline.taskType = ''
      this.formInline.status = ''
      this.getList();
    }
  }
}
</script>

<style scoped>
  /*样式无法修改时  用 /deep/ 或 ::v-deep 操作符取而代之*/
  /deep/ .el-tabs__item.is-active {
    color: #1074fd;
  }
  /deep/ .el-tabs__item:hover {
    color: #1074fd;
    cursor: pointer;
  }
  /deep/ .el-tabs__active-bar {
    background-color: #1074fd;
  }
  /deep/ .el-table th {
    overflow: hidden;
    background-color: #f2f2f2;
    color: #888888;
  }
  /deep/ .el-dialog__header {
    background-color: #f2f2f2;
  }
  /deep/ .el-table th>.cell {
    color: #1074fd;
  }
</style>
